package calao;

import calao.storage.Field;
import calao.storage.Record;
import calao.storage.Sequence;
import calao.storage.Table;

public class Profile 
{
	
	static final Table TABLE = new Table("calao.Profile"); 

	static final Sequence ID_SEQUENCE = new Sequence("calao.ProfileId");

	static final Field<Integer> ID = 
		TABLE.createField("id", Field.INTEGER);	

	static final Field<String> NAME = 
		TABLE.createField("name", Field.STRING);	

	static final Field<String> PERMISSIONS = 
		TABLE.createField("permission", Field.STRING, true);	

	static {
		TABLE.createPrimaryKeyIndex(ID);
	}
	
	final Server server;
	final int wsid;
	final int id;
	String name;
	String[] permissions;
	
	Profile(Workspace ws, int id, String name, String[] permissions)
	{
		this.server = ws.server;
		this.wsid = ws.id;
		this.id = id;
		this.name = name;
		this.permissions = permissions;
	}
	
	Profile(Workspace ws, Record record)
	{
		this(ws, record.get(ID), record.get(NAME), record.getAll(PERMISSIONS));
	}
	
	public void save()
	{
		server.getWorkspace(wsid).getProfileManager().storeProfile(id, name, permissions);
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String[] getPermissions() {
		return permissions;
	}

	public void setPermissions(String[] permissions) {
		this.permissions = permissions;
	}
		
}
